/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upf.grupE.impl;

import edu.upf.grupE.Controller.AlbumController;
import edu.upf.grupE.Controller.PictureController;
import edu.upf.grupE.Controller.VideoController;
import edu.upf.grupE.Entities.Album;
import edu.upf.grupE.Entities.Picture;
import edu.upf.grupE.Entities.Video;
import edu.upf.grupE.interftest.EventListenerImpl;
import java.util.Vector;
import org.jivesoftware.smack.RosterEntry;

/**
 *
 * @author Madhava Carrillo <madhava at me.com>
 */
public class GUILogic {

    private static EventListenerImpl el;
    private static IM im = new IM(el);

    public static void setEventListener(EventListenerImpl els) {
        el = els;
        im.el = els;
    }

    public static Picture updatePic(Picture updated) {
        return PictureController.getById(PictureController.createOrUpdate(updated));
    }

    public static Video updateVideo(Video updated) {
        return VideoController.getById(VideoController.createOrUpdate(updated));
    }

    public static Vector<Picture> getPicturesByAlbum(Long albumid) {
        return AlbumController.getPicturesById(albumid);
    }

    public static Vector<Video> getVideosByAlbum(Long albumid) {
        return AlbumController.getVideosById(albumid);
    }

    public static void Login(String username, String password) {
        if (im.login(username, password, Config.RESOURCE)) {
            el.setOnline();
        }
    }

    public static void Logout() {
        im.logout();
    }

    public static void sendText(String text, String email) {
        im.sendChat(email, text);
    }

    public static void delPic(Long picid) {
        PictureController.delById(picid);
    }

    public static void delVideo(Long videoid) {
        VideoController.delById(videoid);
    }

    public static Video getByVideoId(Long videoid) {
        return VideoController.getById(videoid);
    }

    public static Picture getByPictureId(Long picid) {
        return PictureController.getById(picid);
    }

    public static Vector<Album> getListAlbums() {
        return AlbumController.getAll();
    }

    public static void AddPic(Picture pic) {
        PictureController.createOrUpdate(pic);
    }

    public static void AddVid(Video vid) {
        VideoController.createOrUpdate(vid);
    }

    public static Album createAlbum(Album newalbum) {
        Long id = AlbumController.createOrUpdate(newalbum);
        return AlbumController.getById(id);
    }

    public static Vector<String> getOntologyes() {
        Vector<String> ontologyes = new Vector<String>();
        ontologyes.add("lugar");
        ontologyes.add("Musica");
        ontologyes.add("animales");
        ontologyes.add("plantas");
        ontologyes.add("Vinos");
        return ontologyes;
    }

    public static Vector<String> getTermsByOntology(String ontology) {
        Vector<String> terms = null;

        //argggg
        return terms;
    }

    public static Vector<RosterEntry> getOnlineContacts() {
        return im.getOnlineContacts();
    }

    public static Vector<RosterEntry> getIlusionOnlineContacts() {
        return im.getIlusionOnlineContacts();
    }

    public static void searchPictureByFreeText(String me, String key) {
        searchProfile searchprofile = new searchProfile(searchProfile.FREETEXT, key);
        System.out.println(key);
        im.sendSearchProfile(searchprofile);
    }

    public static void searchPictureByOntology(String me, String key, String ontology) {
        searchProfile searchprofile = new searchProfile(key, ontology);
        im.sendSearchProfile(searchprofile);
    }

    public static void searchPictureByNewsTitle(String me, String key) {
        searchProfile searchprofile = new searchProfile(searchProfile.BYNEWSTITLE, key);
        im.sendSearchProfile(searchprofile);
    }

    public static void searchPictureByNewsText(String me, String key) {
        searchProfile searchprofile = new searchProfile(searchProfile.BYNEWSTEXT, key);
        im.sendSearchProfile(searchprofile);
    }

    public static void searchPictureByNewsAdjacent(String me, String key) {
        searchProfile searchprofile = new searchProfile(searchProfile.BYNEWSADJACENT, key);
        im.sendSearchProfile(searchprofile);
    }

    public static void sendVideoRequest(String user, String ip, Long VideoId, int port) {
        im.requestVideo(user, ip, port + "", VideoId + "");
    }

    public static void DeleteVideo(Long id) {
        VideoController.delById(id);
    }

    public static void DeleteAlbum(Long id) {
        AlbumController.delById(id);
    }

    public static void DeletePicture(Long id) {
        PictureController.delById(id);
    }

    public static void sendPictureRequest(String user, Long PictureId) {
        im.requestPicture(user, PictureId + "");
    }

    public static void requestVideoList(String to) {
        im.sendVideoList(to);
    }
}
